
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>1.两数之和 · Gary的小窝</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Gary">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-solarizedlight.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="2.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    写在前面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./">
            
                    
                    Leetcode之旅
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.2.1" data-path="1.html">
            
                <a href="1.html">
            
                    
                    1.两数之和
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="2.html">
            
                <a href="2.html">
            
                    
                    2.两数相加
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="3.html">
            
                <a href="3.html">
            
                    
                    3.无重复字符的最长子串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="4.html">
            
                <a href="4.html">
            
                    
                    4.寻找两个有序数组的中位数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="6.html">
            
                <a href="6.html">
            
                    
                    6.Z字形变换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="9.html">
            
                <a href="9.html">
            
                    
                    9.回文数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="11.html">
            
                <a href="11.html">
            
                    
                    11.盛最多水的容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="12.html">
            
                <a href="12.html">
            
                    
                    12.整数转罗马数字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="13.html">
            
                <a href="13.html">
            
                    
                    13.罗马数字转整数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="14.html">
            
                <a href="14.html">
            
                    
                    14.最长公共前缀
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="322.html">
            
                <a href="322.html">
            
                    
                    322.零钱兑换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="72.html">
            
                <a href="72.html">
            
                    
                    72.编辑距离
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../flutter/">
            
                <a href="../flutter/">
            
                    
                    Flutter从入门到放弃
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../flutter/dart1.html">
            
                <a href="../flutter/dart1.html">
            
                    
                    1.Dart语言(1)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../flutter/dart2.html">
            
                <a href="../flutter/dart2.html">
            
                    
                    2.Dart语言(2)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../flutter/widget1.html">
            
                <a href="../flutter/widget1.html">
            
                    
                    3.Flutter初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../flutter/containerText.html">
            
                <a href="../flutter/containerText.html">
            
                    
                    4.Container和Text组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../flutter/image.html">
            
                <a href="../flutter/image.html">
            
                    
                    5.Image组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../flutter/chapter2.html">
            
                <a href="../flutter/chapter2.html">
            
                    
                    6.Flutter 技术总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../vue/">
            
                <a href="../vue/">
            
                    
                    Vue组件精讲
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../vue/1.html">
            
                <a href="../vue/1.html">
            
                    
                    1.provide/inject
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../vue/2.html">
            
                <a href="../vue/2.html">
            
                    
                    2.手动实现broadcast和dispatch方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../js/form.html">
            
                <a href="../js/form.html">
            
                    
                    3.自己动手实现带校验的Form表单组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../js/">
            
                <a href="../js/">
            
                    
                    JavaScript进阶
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../js/proxy.html">
            
                <a href="../js/proxy.html">
            
                    
                    1.Vue.js 3.0中的响应式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../js/el.html">
            
                <a href="../js/el.html">
            
                    
                    2.Element UI 源码初探
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../js/bind.html">
            
                <a href="../js/bind.html">
            
                    
                    3.bind的模拟实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../js/proto.html">
            
                <a href="../js/proto.html">
            
                    
                    4.JS原型和原型链
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../js/call.html">
            
                <a href="../js/call.html">
            
                    
                    5.模拟实现call和apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../js/ui.html">
            
                <a href="../js/ui.html">
            
                    
                    6.使用Vue cli3搭建组件库并发布到 npm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="../js/microFE.html">
            
                <a href="../js/microFE.html">
            
                    
                    7.记一次基于qiankun的微前端的改造
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="../js/git.html">
            
                <a href="../js/git.html">
            
                    
                    8.Git的使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../vueLibrary/">
            
                <a href="../vueLibrary/">
            
                    
                    基于Vue的PC端的组件库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../vueLibrary/1.html">
            
                <a href="../vueLibrary/1.html">
            
                    
                    1.环境搭建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../life/">
            
                <a href="../life/">
            
                    
                    网事杂谈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../life/1.html">
            
                <a href="../life/1.html">
            
                    
                    1.周杰伦专辑赏析--叶惠美
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../life/2.html">
            
                <a href="../life/2.html">
            
                    
                    2.周杰伦专辑赏析--七里香
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >1.两数之和</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#001-&#x4E24;&#x6570;&#x4E4B;&#x548C;"><b></b>001. &#x4E24;&#x6570;&#x4E4B;&#x548C;</a></li><li><span class="title-icon "></span><a href="#&#x4E00;-&#x9898;&#x76EE;&#x63CF;&#x8FF0;"><b></b>&#x4E00; &#x9898;&#x76EE;&#x63CF;&#x8FF0;</a></li><li><span class="title-icon "></span><a href="#&#x4E8C;-&#x89E3;&#x9898;&#x8FC7;&#x7A0B;"><b></b>&#x4E8C; &#x89E3;&#x9898;&#x8FC7;&#x7A0B;</a></li></ul></div><a href="#001-&#x4E24;&#x6570;&#x4E4B;&#x548C;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-16 19:08:00
 * @LastEditTime: 2019-08-17 16:07:48
 * @LastEditors: Please set LastEditors
 -->
<h1 id="001-&#x4E24;&#x6570;&#x4E4B;&#x548C;"><a name="001-&#x4E24;&#x6570;&#x4E4B;&#x548C;" class="anchor-navigation-ex-anchor" href="#001-&#x4E24;&#x6570;&#x4E4B;&#x548C;"><i class="fa fa-link" aria-hidden="true"></i></a>001. &#x4E24;&#x6570;&#x4E4B;&#x548C;</h1>
<h1 id="&#x4E00;-&#x9898;&#x76EE;&#x63CF;&#x8FF0;"><a name="&#x4E00;-&#x9898;&#x76EE;&#x63CF;&#x8FF0;" class="anchor-navigation-ex-anchor" href="#&#x4E00;-&#x9898;&#x76EE;&#x63CF;&#x8FF0;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E00; &#x9898;&#x76EE;&#x63CF;&#x8FF0;</h1>
<blockquote>
<p>&#x7ED9;&#x5B9A;&#x4E00;&#x4E2A;&#x6574;&#x6570;&#x6570;&#x7EC4; nums &#x548C;&#x4E00;&#x4E2A;&#x76EE;&#x6807;&#x503C; target&#xFF0C;&#x8BF7;&#x4F60;&#x5728;&#x8BE5;&#x6570;&#x7EC4;&#x4E2D;&#x627E;&#x51FA;&#x548C;&#x4E3A;&#x76EE;&#x6807;&#x503C;&#x7684;&#x90A3; &#x4E24;&#x4E2A; &#x6574;&#x6570;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x4ED6;&#x4EEC;&#x7684;&#x6570;&#x7EC4;&#x4E0B;&#x6807;&#x3002;
&#x4F60;&#x53EF;&#x4EE5;&#x5047;&#x8BBE;&#x6BCF;&#x79CD;&#x8F93;&#x5165;&#x53EA;&#x4F1A;&#x5BF9;&#x5E94;&#x4E00;&#x4E2A;&#x7B54;&#x6848;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x4F60;&#x4E0D;&#x80FD;&#x91CD;&#x590D;&#x5229;&#x7528;&#x8FD9;&#x4E2A;&#x6570;&#x7EC4;&#x4E2D;&#x540C;&#x6837;&#x7684;&#x5143;&#x7D20;&#x3002;</p>
</blockquote>
<p>&#x793A;&#x4F8B;&#xFF1A;</p>
<pre class="language-"><code>&#x7ED9;&#x5B9A; nums = [2, 7, 11, 15], target = 9

&#x56E0;&#x4E3A; nums[0] + nums[1] = 2 + 7 = 9
&#x6240;&#x4EE5;&#x8FD4;&#x56DE; [0, 1]
</code></pre><h1 id="&#x4E8C;-&#x89E3;&#x9898;&#x8FC7;&#x7A0B;"><a name="&#x4E8C;-&#x89E3;&#x9898;&#x8FC7;&#x7A0B;" class="anchor-navigation-ex-anchor" href="#&#x4E8C;-&#x89E3;&#x9898;&#x8FC7;&#x7A0B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E8C; &#x89E3;&#x9898;&#x8FC7;&#x7A0B;</h1>
<p>&#x62FF;&#x5230;&#x9898;&#x76EE;&#x5F88;&#x5BB9;&#x6613;&#x60F3;&#x5230;&#x6570;&#x7EC4;&#x5FAA;&#x73AF;&#x904D;&#x5386;&#x5224;&#x65AD;&#xFF0C;&#x4E8E;&#x662F;&#x6211;&#x4E09;&#x4E0B;&#x4E94;&#x9664;&#x4E8C;&#x5199;&#x51FA;&#x4E86;&#x8FD9;&#x6837;&#x7684;&#x4EE3;&#x7801;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment">/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */</span>
<span class="token keyword">var</span> <span class="token function-variable function">twoSum</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">nums<span class="token punctuation">,</span> target</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span>nums <span class="token keyword">instanceof</span> <span class="token class-name">Array</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span> <span class="token punctuation">;</span> i <span class="token operator">&lt;</span> nums<span class="token punctuation">.</span>length <span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">let</span> j<span class="token operator">=</span> i<span class="token operator">+</span><span class="token number">1</span> <span class="token punctuation">;</span>j<span class="token operator">&lt;</span>nums<span class="token punctuation">.</span>length<span class="token punctuation">;</span>j<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span>nums<span class="token punctuation">[</span>i<span class="token punctuation">]</span> <span class="token operator">+</span> nums<span class="token punctuation">[</span>j<span class="token punctuation">]</span> <span class="token operator">===</span> target<span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token keyword">return</span> <span class="token punctuation">[</span>i<span class="token punctuation">,</span>j<span class="token punctuation">]</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x4F7F;&#x7528;&#x53CC;&#x5C42;&#x5FAA;&#x73AF;&#x53BB;&#x904D;&#x5386;&#x6570;&#x7EC4;&#xFF0C;&#x5982;&#x679C;&#x627E;&#x7684;&#x5230;&#x5C31;&#x8FD4;&#x56DE;&#x7D22;&#x5F15;&#x503C;&#xFF0C;&#x8FD9;&#x4E2A;&#x7B97;&#x6CD5;&#x7684;&#x590D;&#x6742;&#x5EA6;&#x662F;O&#xFF08;n2&#xFF09;. &#x6211;&#x6EE1;&#x6000;&#x6B23;&#x559C;&#x7684;&#x63D0;&#x4EA4;&#x4EE3;&#x7801;&#x53BB;&#x9A8C;&#x8BC1;&#x7B54;&#x6848;&#xFF0C;&#x5F97;&#x5230;&#x7684;&#x7ED3;&#x679C;&#x662F;&#x901A;&#x8FC7;&#xFF0C;&#x4F46;&#x662F;&#x590D;&#x6742;&#x5EA6;&#x6709;&#x4E9B;&#x8FC7;&#x9AD8;&#x4E86;,&#x5185;&#x5B58;&#x5360;&#x4E5F;&#x6709;&#x70B9;&#x5927;</p>
<blockquote>
<p>&#x5185;&#x5B58;&#x6D88;&#x8017; :34.7 MB, &#x5728;&#x6240;&#x6709; JavaScript &#x63D0;&#x4EA4;&#x4E2D;&#x51FB;&#x8D25;&#x4E86;41.93%&#x7684;&#x7528;&#x6237;</p>
</blockquote>
<p>&#x6240;&#x4EE5;&#x6211;&#x82E6;&#x601D;&#x51A5;&#x60F3;&#xFF0C;&#x53EF;&#x4E0D;&#x53EF;&#x4EE5;&#x4E0D;&#x7528;&#x4E8C;&#x6B21;&#x5FAA;&#x73AF;&#x7684;&#x65B9;&#x5F0F;&#x89E3;&#x9898;&#x3002;&#x4E8E;&#x662F;&#x6211;&#x60F3;&#x5230;&#x4E86; indexOf</p>
<blockquote>
<p>indexOf()&#xFF1A;&#x5224;&#x65AD;&#x6570;&#x7EC4;&#x4E2D;&#x662F;&#x5426;&#x5B58;&#x5728;&#x5224;&#x65AD;&#x6761;&#x4EF6;&#x4E2D;&#x7684;&#x503C;&#x3002;&#x5982;&#x679C;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;&#x7B2C;&#x4E00;&#x6B21;&#x51FA;&#x73B0;&#x7684;&#x7D22;&#x5F15;&#xFF1B;&#x5982;&#x679C;&#x4E0D;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; -1&#x3002;</p>
</blockquote>
<p>&#x4E8E;&#x662F;&#x5C31;&#x4F1A;&#x6709;&#x4E86;&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;</p>
<pre class="language-"><code class="lang-javascript"><span class="token comment">/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 */</span>
<span class="token keyword">var</span> <span class="token function-variable function">twoSum</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">nums<span class="token punctuation">,</span> target</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">let</span> result <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
  nums<span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">item<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span>nums<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span>target <span class="token operator">-</span> item<span class="token punctuation">)</span> <span class="token operator">&gt;</span> <span class="token operator">-</span><span class="token number">1</span> <span class="token operator">&amp;&amp;</span> nums<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span>target <span class="token operator">-</span> item<span class="token punctuation">)</span> <span class="token operator">!=</span> index<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      result <span class="token operator">=</span> <span class="token punctuation">[</span>index<span class="token punctuation">,</span> nums<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span>target <span class="token operator">-</span> item<span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">sort</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">a<span class="token punctuation">,</span> b</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> a <span class="token operator">&gt;</span> b<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">return</span> result<span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x901A;&#x8FC7;&#x904D;&#x5386;&#x4E00;&#x6B21;&#x6570;&#x7EC4; &#xFF0C;&#x4F7F;&#x7528; indexOf() &#x5BFB;&#x627E;&#x9664;&#x5F53;&#x524D; item &#x7684; index &#x4E4B;&#x5916;&#x548C; item &#x76F8;&#x52A0;&#x4E4B;&#x548C;&#x4E3A; target &#x7684;&#x7ED3;&#x679C;&#x3002;</p>
<p>&#x6700;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x8FD4;&#x56DE;&#x67E5;&#x627E;&#x7684;&#x6700;&#x65B0;&#x7ED3;&#x679C;&#xFF0C;&#x8BE5;&#x7ED3;&#x679C;&#x8FDB;&#x884C;&#x4E86;&#x6392;&#x5E8F;&#xFF08;[4, 2] &#x7684;&#x8FD4;&#x56DE;&#x901A;&#x8FC7; sort() &#x6392;&#x5E8F;&#x53D8;&#x6210; [2, 4]&#xFF09;</p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; YoungGary 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-01-03 16:31:06
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: Leetcode之旅">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="2.html" class="navigation navigation-next " aria-label="Next page: 2.两数相加">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"1.两数之和","level":"1.2.1","depth":2,"next":{"title":"2.两数相加","level":"1.2.2","depth":2,"path":"leetcode/2.md","ref":"leetcode/2.md","articles":[]},"previous":{"title":"Leetcode之旅","level":"1.2","depth":1,"path":"leetcode/README.md","ref":"leetcode/README.md","articles":[{"title":"1.两数之和","level":"1.2.1","depth":2,"path":"leetcode/1.md","ref":"leetcode/1.md","articles":[]},{"title":"2.两数相加","level":"1.2.2","depth":2,"path":"leetcode/2.md","ref":"leetcode/2.md","articles":[]},{"title":"3.无重复字符的最长子串","level":"1.2.3","depth":2,"path":"leetcode/3.md","ref":"leetcode/3.md","articles":[]},{"title":"4.寻找两个有序数组的中位数","level":"1.2.4","depth":2,"path":"leetcode/4.md","ref":"leetcode/4.md","articles":[]},{"title":"6.Z字形变换","level":"1.2.5","depth":2,"path":"leetcode/6.md","ref":"leetcode/6.md","articles":[]},{"title":"9.回文数","level":"1.2.6","depth":2,"path":"leetcode/9.md","ref":"leetcode/9.md","articles":[]},{"title":"11.盛最多水的容器","level":"1.2.7","depth":2,"path":"leetcode/11.md","ref":"leetcode/11.md","articles":[]},{"title":"12.整数转罗马数字","level":"1.2.8","depth":2,"path":"leetcode/12.md","ref":"leetcode/12.md","articles":[]},{"title":"13.罗马数字转整数","level":"1.2.9","depth":2,"path":"leetcode/13.md","ref":"leetcode/13.md","articles":[]},{"title":"14.最长公共前缀","level":"1.2.10","depth":2,"path":"leetcode/14.md","ref":"leetcode/14.md","articles":[]},{"title":"322.零钱兑换","level":"1.2.11","depth":2,"path":"leetcode/322.md","ref":"leetcode/322.md","articles":[]},{"title":"72.编辑距离","level":"1.2.12","depth":2,"path":"leetcode/72.md","ref":"leetcode/72.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["theme-comscore","prism","-highlight","copy-code-button","search-pro","-search","-lunr","expandable-chapters","splitter","-sharing","tbfed-pagefooter","anchor-navigation-ex"],"styles":{},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy YoungGary 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prismjs/themes/prism-solarizedlight.css"],"lang":{"shell":"bash"}},"splitter":{},"search-pro":{},"fontsettings":{"theme":"white","family":"sans","size":2},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"theme-comscore":{},"copy-code-button":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"Gary","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Gary的小窝","language":"zh-hans","gitbook":"*","description":"Gary的小窝. 里面包含了个人撰写的技术文章"},"file":{"path":"leetcode/1.md","mtime":"2020-01-03T08:31:06.074Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-09-09T14:10:10.930Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

